<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="时间">
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="totals"
      :page-size="pagesize"
      :current-page="currentpage"
      @current-change="gotpage">
    </el-pagination>
  </div>
</template>

<script>
//局部使用axios
import axios from "axios";
export default {
  data() {
    return {
      totals: 0,
      pagesize: 5,
      currentpage: 1,
      tableData: []
    }
  },
  methods: {
    getdate() {
      //接收模拟后端参数
      let param = {"currentPage": this.currentpage, "pageSize": this.pagesize}
      //axios发送请求到后端
      axios.post("/user/list", param)
        .then(result => {
          // 代表着当前的请求 已经到后端了 等待后端返回结果后 会走then里面来！
          // result 就是我们后端返回的结果集
          // 我们要做什么事情？？？？ 将后端返回的数据 赋值到我们data函数中的 tableData
          this.tableData = result.data.data
          this.totals = result.data.totals
        })
        .catch(result => {
          // 压根就没有请求到后端 404
          alert("网络异常，请稍后再试")
        })
    },
    gotpage(curr) {
      this.currentpage = curr;
      this.getdate();
    }
  },
  mounted() {
    this.getdate()
  }
}
</script>


